/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package base.Skills;

import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import java.io.IOException;
import java.util.TreeMap;

/**
 *
 * @author Paulo
 */
public class SkillManager implements Savable {
    
    private TreeMap<String, Skill> skills;
    private Skill slot;
    
    private int countWater = 0;
    private int countFire = 0;
    private int countEarth = 0;
    private int countWind = 0;
    private int countMud = 0;
    private int countThunder = 0;
    private int countMagma = 0;
    private int countSteam = 0;
    private int countLight = 0;
    private int countDark = 0;
    
    public SkillManager() {
        this.skills = new TreeMap<String, Skill>();
    }
    
    public void addSkill(Skill skill) {
        this.skills.put(skill.getName(), skill);
    }
    
    public void removeSkill(Skill skill) {
        this.skills.remove(skill.getName());
    }
    
    public void setSkill(Skill magic) {
        this.slot = magic;
    }
    
    public Skill getSkill() {
        return this.slot;
    }
    
    public int getLevelDark() {
        return countDark / 1000;
    }
    
    public int getLevelEarth() {
        return countEarth / 1000;
    }
    
    public int getLevelFire() {
        return countFire / 1000;
    }
    
    public int getLevelLight() {
        return countLight / 1000;
    }
    
    public int getLevelWater() {
        return countWater / 1000;
    }
    
    public int getLevelWind() {
        return countWind / 1000;
    }
    
    public int getLevelMud() {
        return countMud / 1000;
    }
    
    public int getLevelMagma() {
        return countMagma / 1000;
    }
    
    public int getLevelThunder() {
        return countThunder / 1000;
    }
    
    public int getLevelSteam() {
        return countSteam / 1000;
    }

    public void write(JmeExporter ex) throws IOException {
        OutputCapsule out = ex.getCapsule(this);
        
        Skill[] array = new Skill[0];
        array = skills.values().toArray(array);
        
        out.write(array, "skills", null);
        out.write(slot, "slot", null);
        out.write(countDark, "countDark", 0);
        out.write(countEarth, "countEarth", 0);
        out.write(countFire, "countFire", 0);
        out.write(countLight, "countLight", 0);
        out.write(countMagma, "countMagma", 0);
        out.write(countMud, "countMud", 0);
        out.write(countSteam, "countSteam", 0);
        out.write(countThunder, "countThunder", 0);
        out.write(countWater, "countWater", 0);
        out.write(countWind, "countWind", 0);
    }

    public void read(JmeImporter im) throws IOException {
        InputCapsule in = im.getCapsule(this);
        
        Skill[] array = (Skill[]) in.readSavableArray("skills", new Skill[0]);
        for (Skill s : array) {
            skills.put(s.getName(), s);
        }
        slot = (Skill) in.readSavable("slot", null);
        countDark = in.readInt("countDark", 0);
        countEarth = in.readInt("countEarth", 0);
        countFire = in.readInt("countFire", 0);
        countLight = in.readInt("countLight", 0);
        countMagma = in.readInt("countMagma", 0);
        countMud = in.readInt("countMud", 0);
        countSteam = in.readInt("countSteam", 0);
        countThunder = in.readInt("countThunder", 0);
        countWater = in.readInt("countWater", 0);
        countWind = in.readInt("countWind", 0);
    }
}
